package main
 
import (
	"log"
  "github.com/prometheus/client_golang/prometheus"
)

/*
 Prometheus Gauge类型 指标定义
*/
var  (
  // array
  GaugeVec [32] *prometheus.GaugeVec
)

func Initialize_GaugeVec_List() {
	var idx int = 0
	for _, Metriclabel := range GlobalConfig.Metriclabels {
		for _, Metric := range Metriclabel.Metrics {
			GaugeVec[idx] = prometheus.NewGaugeVec(
				prometheus.GaugeOpts{
					Namespace: GlobalConfig.Exporter.Namespace,
					Subsystem: Metriclabel.Subsystem,
					Name: Metric.Name,
					Help: Metric.Help,
				},
				[]string{"tag", "cmd"},
			)
			idx++
		}
	}
}

func MustRegister_GaugeVec_List() {
	// gauge metrics could use Prometheus' 'predict_linear' method
	// GaugeVec import from metrics.go file
	var idx int = 0
	for _, Metriclabel := range GlobalConfig.Metriclabels {
		for _, Metric := range Metriclabel.Metrics {
			log.Printf("Regist metric: %s", Metric.ShellCmd)
			prometheus.MustRegister(GaugeVec[idx])
			idx++
		}
	}
}

func ConstructMetric() {
	var idx int = 0
	for _, Metriclabel := range GlobalConfig.Metriclabels {
		for _, Metric := range Metriclabel.Metrics {
			log.Printf("Construct metric: %s", Metric.ShellCmd)

			val := ShellCmdExecutor(Metric.ShellCmd, Metric.Tag)
			GaugeVec[idx].With(prometheus.Labels{ 
			"tag":    Metric.Tag,
			"cmd":   Metric.ShellCmd }).Set( val )

			idx++
		}
	}
}
